package com.heima.controller;

import com.heima.pojo.vo.TaskAllVo;
import com.heima.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/api/task-service/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/taskReportInfo/{start}/{end}")
    public List<TaskAllVo> taskReportInfo(
            @PathVariable("start") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @PathVariable("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        return taskService.getTotal(start, end);
    }
  /*  @GetMapping("/taskReportInfo")
    public List<TaskAllVo> taskReportInfo(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                                          @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end){
        return taskService.getTotal(start,end);
    }
*/
/*
  @GetMapping("/taskReportInfo/{start}/{end}")
  public List<TaskAllVo> taskReportInfo(
          @PathVariable String start,
          @PathVariable String end) {
      // 手动解码和转换日期
      LocalDateTime startDate = LocalDateTime.parse(
              URLDecoder.decode(start, StandardCharsets.UTF_8),
              DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
      );

      LocalDateTime endDate = LocalDateTime.parse(
              URLDecoder.decode(end, StandardCharsets.UTF_8),
              DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
      );
      return taskService.getTotal(startDate, endDate);
  }
*/

}
